home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / tex / dvi / dvipssrc.zoo / dvips.c < prev    next >
C/C++ Source or Header  |  1991-04-22  |  19KB  |  637 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. /*
  59.  *   This is the main routine.
  60.  */
  61. #ifndef DEFRES
  62. #define DEFRES (300)
  63. #endif
  64.  
  65. #include "structures.h" /* The copyright notice there is included too! */
  66. #ifdef VMS
  67. #define GLOBAL globaldef
  68. #include climsgdef
  69. #include ctype
  70. #include descrip
  71. #endif
  72. /*
  73.  *   First we define some globals.
  74.  */
  75. #ifdef VMS
  76.     static char ofnme[252],infnme[252],pap[40],thh[20];
  77. #endif
  78. fontdesctype *fonthead ;      /* list of all fonts mentioned so far */
  79. fontdesctype *curfnt ;        /* the currently selected font */
  80. sectiontype *sections ;       /* sections to process document in */
  81. Boolean manualfeed ;          /* manual feed? */
  82. Boolean compressed ;          /* compressed? */
  83. Boolean safetyenclose ;       /* enclose in save/restore for stupid spoolers? */
  84. Boolean removecomments = 1 ;  /* remove comments from included PS? */
  85. Boolean nosmallchars ;        /* disable small char optimization for X4045? */
  86. int collatedcopies = 1 ;      /* how many collated copies? */
  87. int sectioncopies = 1 ;       /* how many times to repeat each section? */
  88. shalfword linepos = 0 ;       /* where are we on the line being output? */
  89. integer maxpages ;            /* the maximum number of pages */
  90. Boolean notfirst, notlast ;   /* true if a first page was specified */
  91. Boolean sendcontrolD ;        /* should we send a control D at end? */
  92. integer firstpage ;           /* the number of the first page if specified */
  93. integer lastpage ;
  94. integer firstseq ;
  95. integer lastseq ;
  96. int numcopies ;               /* number of copies of each page to print */
  97. char *oname ;                 /* output file name */
  98. char *iname ;                 /* dvi file name */
  99. char *strings ;               /* strings for program */
  100. char *nextstring, *maxstring ; /* string pointers */
  101. FILE *dvifile, *bitfile ;     /* dvi and output files */
  102. quarterword *curpos ;         /* current position in virtual character packet */
  103. quarterword *curlim ;         /* final byte in virtual character packet */
  104. fontmaptype *ffont ;          /* first font in current frame */
  105. real conv ;                   /* conversion ratio, pixels per DVI unit */
  106. real vconv ;                  /* conversion ratio, pixels per DVI unit */
  107. real alpha ;                  /* conversion ratio, DVI unit per TFM unit */
  108. integer mag ;                 /* the magnification of this document */
  109. Boolean overridemag ;         /* substitute for mag value in DVI file? */
  110. int actualdpi = DEFRES ;      /* the actual resolution of the printer */
  111. int vactualdpi = DEFRES ;      /* the actual resolution of the printer */
  112. int maxdrift ;                /* max pixels away from true rounded position */
  113. int vmaxdrift ;                /* max pixels away from true rounded position */
  114. char *paperfmt                /* paper format */
  115. #ifdef DEFPFMT
  116.     = DEFPFMT ;
  117. #else
  118.     ;
  119. #endif
  120. int landscape = 0 ;           /* landscape mode */
  121. integer fontmem ;             /* memory remaining in printer */
  122. integer pagecount ;           /* page counter for the sections */
  123. integer pagenum ;             /* the page number we currently look at */
  124. long bytesleft ;              /* number of bytes left in raster */
  125. quarterword *raster ;         /* area for raster manipulations */
  126. integer hh, vv ;              /* horizontal and vertical pixel positions */
  127. char *tfmpath = TFMPATH ;     /* pointer to directories for tfm files */
  128. char *pkpath = PKPATH ;       /* pointer to directories for pk files */
  129. char *vfpath = VFPATH ;       /* pointer to directories for vf files */
  130. char *figpath = FIGPATH ;     /* pointer to directories for figure files */
  131. char *headerpath = HEADERPATH ; /* pointer to directories for header files */
  132. char *configpath = CONFIGPATH;  /* where to find config files */
  133. #ifdef SEARCH_SUBDIRECTORIES
  134. char *fontsubdirpath = FONTSUBDIRPATH ;
  135. #endif
  136. #ifdef FONTLIB
  137. char *flipath = FLIPATH ;     /* pointer to directories for fli files */
  138. char *fliname = FLINAME ;     /* pointer to names of fli files */
  139. #endif
  140. integer swmem ;               /* font memory in the PostScript printer */
  141. int quiet ;                   /* should we only print errors to stderr? */
  142. int filter ;                  /* act as filter default output to stdout,
  143.                                                default input to stdin? */
  144. int prettycolumn ;            /* the column we are at when running pretty */
  145. int totalpages = 0 ;          /* total number of pages */
  146. Boolean reverse ;             /* are we going reverse? */
  147. Boolean usesPSfonts ;         /* do we use local PostScript fonts? */
  148. Boolean usesspecial ;         /* do we use \special? */
  149. Boolean headers_off ;         /* do we send headers or not? */
  150. char *headerfile ;            /* default header file */
  151. char *warningmsg ;            /* a message to write, if set in config file */
  152. Boolean multiplesects ;       /* more than one section? */
  153. Boolean disablecomments ;     /* should we suppress any EPSF comments? */
  154. char *printer ;               /* what printer to send this to? */
  155. char *mfmode ;                /* default MF mode */
  156. frametype frames[MAXFRAME] ;  /* stack for virtual fonts */
  157. fontdesctype *baseFonts[256] ; /* base fonts for dvi file */
  158. integer pagecost;               /* memory used on the page being prescanned */
  159. int delchar;                    /* characters to delete from prescanned page */
  160. integer fsizetol;               /* max dvi units error for psfile font sizes */
  161. Boolean includesfonts;          /* are fonts used in included psfiles? */
  162. fontdesctype *fonthd[MAXFONTHD];/* list headers for included fonts of 1 name */
  163. int nextfonthd;                 /* next unused fonthd[] index */
  164. char xdig[256];                 /* table for reading hexadecimal digits */
  165. char banner[] = BANNER ;        /* our startup message */
  166. Boolean noenv ;                 /* ignore PRINTER envir variable? */
  167. extern int dontmakefont ;
  168. #ifdef DEBUG
  169. integer debug_flag = 0;
  170. #endif /* DEBUG */
  171. /*
  172.  *   This routine calls the following externals:
  173.  */
  174. extern void outbangspecials() ;
  175. extern void prescanpages() ;
  176. extern void initprinter() ;
  177. extern void cleanprinter() ;
  178. extern void dosection() ;
  179. extern void getdefaults() ;
  180. extern void cmdout() ;
  181. extern void numout() ;
  182. extern int add_header() ;
  183. extern char *strcpy() ;
  184. extern void checkenv() ;
  185. extern void getpsinfo() ;
  186. #ifdef FONTLIB
  187. extern void fliload() ;
  188. #endif
  189. /*
  190.  *   This error routine prints an error message; if the first
  191.  *   character is !, it aborts the job.
  192.  */
  193. static char *progname ;
  194. void
  195. error(s)
  196.     char *s ;
  197. {
  198.    extern void exit() ;
  199.  
  200.    (void)fprintf(stderr, "%s: %s\n", progname, s) ;
  201.    if (*s=='!') {
  202.       if (bitfile != NULL) {
  203.          cleanprinter() ;
  204.       }
  205.       exit(1) ; /* fatal */
  206.    }
  207. }
  208.  
  209. /*
  210.  *   Initialize sets up all the globals and data structures.
  211.  */
  212. void
  213. initialize()
  214. {
  215.    extern char *malloc() ;
  216.    int i;
  217.    char *s;
  218.  
  219.    nextfonthd = 0;
  220.    for (i=0; i<256; i++)
  221.       xdig[i] = 0;
  222.    i = 0;
  223.    for (s="0123456789ABCDEF"; *s!=0; s++)
  224.       xdig[*s] = i++;
  225.    i = 10;
  226.    for (s="abcdef"; *s!=0; s++)
  227.       xdig[*s] = i++;
  228.    strings = malloc(STRINGSIZE) ;
  229.    if (strings == 0)
  230.       error("! no memory for strings") ;
  231.    maxpages = 100000 ;
  232.    numcopies = 1 ;
  233.    nextstring = strings ;
  234.    iname = strings ;
  235.    *nextstring++ = 0 ;
  236.    maxstring = strings + STRINGSIZE - 200 ;
  237.    bitfile = NULL ;
  238.    bytesleft = 0 ;
  239.    swmem = SWMEM ;
  240.    oname = OUTPATH ;
  241.    sendcontrolD = 0 ;
  242.    multiplesects = 0 ;
  243.    disablecomments = 0 ;
  244.    maxdrift = -1 ;
  245.    vmaxdrift = -1 ;
  246. }
  247. /*
  248.  *   This routine copies a string into the string `pool', safely.
  249.  */
  250. char *
  251. newstring(s)
  252.    char *s ;
  253. {
  254.    int l ;
  255.  
  256.    if (s == NULL)
  257.       return(NULL) ;
  258.    l = strlen(s) ;
  259.    if (nextstring + l >= maxstring)
  260.       error("! out of string space") ;
  261.    (void)strcpy(nextstring, s) ;
  262.    s = nextstring ;
  263.    nextstring += l + 1 ;
  264.    return(s) ;
  265. }
  266. /*
  267.  *   Finally, our main routine.
  268.  */
  269. #ifdef VMS
  270. main()
  271. #else
  272. void main(argc, argv)
  273.     int argc ;
  274.     char *argv[